<?php
/*
 * 手机客户端拍卖-专场列表页接口
 * 2014-05-27
 */
include "../inc/public_header.php";
include "../inc/version_utills.php";

$reJson = array(); //构建返回值
$reJson["success"] = "1";
/*
 * 常量
 */

$sql = "SELECT 
				asid
				,aspecial
				,astopic
				,(select count(aid) from auction where is_delete=0 and atag>0  and asid=auction_special.asid) as count
				,NOW() as ntime
				,asclosetime 
				,if((now() < asprevclosetime),0,if((now() between asopentime and asclosetime),1,2)) as type
		from auction_special 
		where astag=1 
		order by type,asid desc LIMIT 0,15";

$eventArr = $db->queryArray($sql);

$tempArr = array();
for($i=0;$i<count($eventArr);$i++){
	if ($eventArr[$i]["ntime"]<=$eventArr[$i]["asclosetime"]){
		array_unshift($tempArr, $eventArr[$i]);
	}else{
		$tempArr[] = $eventArr[$i];
	}
}

$list = array();
for($i=0;$i<count($tempArr);$i++){
	$listjson = array(
		 "asid"=>$tempArr[$i]["asid"]
		,"name"=>$tempArr[$i]["aspecial"]
		,"iconUrl"=>$tempArr[$i]["astopic"]
		,"count"=>$tempArr[$i]["count"]
		,"eventType"=>$tempArr[$i]["type"]
	);
	
	
	$list[] = $listjson;
}

$reJson["list"] = $list;
echo json_encode($reJson);
die;
?>
